﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLLopHoc.DoiTuongDuLieu;
using QLLopHoc.XuLyDuLieu;


namespace QLLopHoc
{
    public partial class frmThemSVChoLH : Form
    {
        public frmThemSVChoLH(string tenLH)
        {
            InitializeComponent();
            lvDSSV.View = View.Details; 
            lvDSSV.MultiSelect = true; 
            lvDSSV.GridLines = true; 
            lvDSSV.FullRowSelect = true; 
            lvDSSV.HeaderStyle = ColumnHeaderStyle.Nonclickable;
            ColumnHeader ch = new ColumnHeader(); 
            ch.Name = "cSTT"; 
            ch.Text = "STT"; 
            ch.Width = 40; 
            ch.TextAlign = HorizontalAlignment.Center; 
            lvDSSV.Columns.Add(ch); 
            ch = new ColumnHeader(); 
            ch.Name = "cMSSV"; 
            ch.Text = "MSSV"; 
            ch.Width = 100; 
            ch.TextAlign = HorizontalAlignment.Left; 
            lvDSSV.Columns.Add(ch); 
            ch = new ColumnHeader(); 
            ch.Name = "cHoTen"; 
            ch.Text = "Họ tên"; 
            ch.Width = 220; 
            ch.TextAlign = HorizontalAlignment.Left; 
            lvDSSV.Columns.Add(ch);

            List<DTSinhVien> dssv = XLSinhVien.LayDSSVKhongThuocLH(tenLH); 
            
            ListViewItem lvi = null; 
            int i = 1; 
            foreach (DTSinhVien sv in dssv) 
            { 
                lvi = new ListViewItem(i.ToString()); 
                ++i; 
                lvi.Tag = sv; 
                lvi.SubItems.Add(sv.MSSV); 
                lvi.SubItems.Add(sv.Hoten); 
                lvDSSV.Items.Add(lvi); 
            }
        }

        private void btnBo_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        public List<DTSinhVien> DSSV
        {
            get
            {
                List<DTSinhVien> ds = new List<DTSinhVien>();
                ListView.SelectedListViewItemCollection dsSelect = lvDSSV.SelectedItems;
                foreach (ListViewItem lvi in dsSelect)
                {
                    ds.Add((DTSinhVien)lvi.Tag);
                }
                return ds;
            }
        }
        
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (lvDSSV.SelectedItems.Count == 0) 
            { 
                MessageBox.Show("Chưa có sinh viên nào được chọn!", "Error"); 
                return; 
            } 
            this.DialogResult = DialogResult.OK;
        }

        
    }
}
